/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wap.rockvilletech.util;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
 *
 * @author Tasnim
 */
public class RequestUrlHelper {
    public static String getRequest_QueryString(HttpServletRequest request) {
        java.util.Map params = request.getParameterMap();
        java.util.Set set = params.keySet();
        java.util.Iterator iter = set.iterator();
        
        String strQueryString = "?";
        while (iter.hasNext()) {
            String strKey = "";
            try {
                strKey = "" + iter.next().toString();
            } catch (Exception exGetKey) {
            }
            String strValue = "";
            try {
                strValue = ((String) request.getParameter(strKey) != null ? request.getParameter(strKey) : "").trim();
            } catch (Exception exGetValue) {
            }
            if (strKey.equalsIgnoreCase("") || strValue.equalsIgnoreCase("")) continue;
            strQueryString += strKey + "=" + strValue + "&";
        }
        strQueryString = strQueryString.replaceAll("^&", "").replaceAll("&$", "");
        
        if(strQueryString.equalsIgnoreCase("?")) strQueryString="";
        
        return strQueryString;
        
    }
    public static String getRequest_QueryString_CurrentPage(HttpServletRequest request,String strCurrentPageName) {
        String strThisPageRequestUrl=getRequest_QueryString(request);
        if(!strThisPageRequestUrl.equalsIgnoreCase("")) strThisPageRequestUrl=strCurrentPageName+strThisPageRequestUrl;
        return strThisPageRequestUrl;
        
    }

}
